/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Singleton;

import java.util.concurrent.Semaphore;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author David
 */
public class Avion extends Thread{
    
    String nom;
    private static Aeroport a = null;
    private final Semaphore available = new Semaphore(1, true);
    
    public Avion(String s){
        this.nom = s;
    }
    
    @Override
    public void run(){
        try {
            available.acquire();
            try{
                Thread.sleep(500);
            }catch(Exception e){}
            a = Aeroport.getAeroport();
            System.out.println("je suis dans l'avion "+nom+" sur l'aéroport "+a);
            
        } catch (InterruptedException ex) {
            Logger.getLogger(Avion.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            available.release();
        }
    }
}
